package ynu.edu.dish.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ynu.edu.common.result.Result;
import ynu.edu.dish.service.DishService;
import ynu.edu.dish.service.DishSpecService;
import ynu.edu.dish.vo.DishSpecVO;
import ynu.edu.dish.vo.DishVO;

import java.math.BigDecimal;

/**
 * 内部菜品控制器，提供给其他微服务调用的API
 * 这些API不需要JWT认证
 */
@RestController
@RequestMapping("/internal")
@RequiredArgsConstructor
public class InternalDishController {

    private final DishService dishService;
    private final DishSpecService dishSpecService;

    /**
     * 根据菜品ID获取菜品信息（内部API）
     */
    @GetMapping("/dishes/{id}")
    public Result<DishVO> getDishById(@PathVariable Long id) {
        DishVO dishVO = dishService.getDishById(id);
        return Result.success(dishVO);
    }

    /**
     * 根据菜品规格ID获取菜品规格信息（内部API）
     */
    @GetMapping("/dish-specs/{id}")
    public Result<DishSpecVO> getDishSpecById(@PathVariable Long id) {
        DishSpecVO dishSpecVO = dishSpecService.getDishSpecById(id);
        return Result.success(dishSpecVO);
    }

    /**
     * 根据菜品规格ID获取菜品规格价格（内部API）
     */
    @GetMapping("/dish-specs/{id}/price")
    public Result<BigDecimal> getDishSpecPriceById(@PathVariable Long id) {
        DishSpecVO dishSpecVO = dishSpecService.getDishSpecById(id);
        return dishSpecVO != null ? 
               Result.success(dishSpecVO.getPrice()) : 
               Result.failed("菜品规格不存在");
    }
} 